package com.enation.app.shop.front.policyInsurance.service.impl;

import com.enation.app.shop.front.api.inpolicy.entity.InPolicy;
import com.enation.app.shop.front.policyInsurance.service.InsuranceFarmeOrdMapper;
import com.enation.framework.database.IDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class InsuranceFarmeOrdService implements InsuranceFarmeOrdMapper {
    @Autowired
    private IDaoSupport iDaoSupport;
    @Override
    public List<InPolicy> findInPolicyInfo() {
        String sql = "SELECT * from rbt_inpolicy w WHERE w.`status`=0 and w.is_policy=1";
        return this.iDaoSupport.queryForList(sql,InPolicy.class);
    }

    @Override
    public List<InPolicy> findUnPayInPolicyInfo() {
        String sql = "SELECT * from rbt_inpolicy w WHERE w.`status`=4 and w.is_policy=1";
        return this.iDaoSupport.queryForList(sql,InPolicy.class);
    }

    @Override
    public List<InPolicy> findPassInPolicyInfo() {
        String sql = "SELECT * from rbt_inpolicy w WHERE w.`status`=6 and w.is_policy=1";
        return this.iDaoSupport.queryForList(sql,InPolicy.class);
    }

    @Override
    public List<InPolicy> findNoPassInPolicyInfo(){
        String sql = "SELECT * from rbt_inpolicy w WHERE w.`status` in (2,5) and w.is_policy=1";
        return this.iDaoSupport.queryForList(sql,InPolicy.class);
    }

    @Override
    public InPolicy findFarmInfoByInPolicyId(int inPolicy_id) {
        String sql ="SELECT * from rbt_inpolicy w WHERE w.warranty_id=? and w.is_policy=1";
       List<InPolicy> inPolicyList = this.iDaoSupport.queryForList(sql,inPolicy_id);
        return inPolicyList.get(0);
    }

    @Override
    public InPolicy getInPolicyInfo(int inPolicy_id){
        String sql = "SELECT * from rbt_inpolicy w WHERE w.is_policy=1 and w.warranty_id=?";
        return iDaoSupport.queryForList(sql,InPolicy.class,inPolicy_id).get(0);
    }
}
